package com.fr.report.core;

import com.fr.report.AbstractReport;
import com.fr.report.CellElement;
import com.fr.report.FineBook;
import com.fr.report.FloatElement;
import com.fr.report.RWorkSheet;
import com.fr.report.Report;
import com.fr.report.ReportGetter;
import com.fr.report.cellElement.Formula;
import com.fr.report.io.core.ExcelReport;
import com.fr.report.script.Primitive;
import com.fr.util.Utils;
import java.awt.Dimension;
import java.awt.Point;
import java.io.File;
import java.util.Iterator;

public class ReportHelper
{
  public static Point[] calculateLastColumnAndRowOfFloatElement(Report paramReport, FloatElement paramFloatElement)
  {
    int i = paramFloatElement.getColumn();
    int j = paramFloatElement.getRow();
    int k = paramFloatElement.getLeftDistance();
    int l = paramFloatElement.getTopDistance();
    Dimension localDimension = paramFloatElement.getSize();
    DynamicValueList localDynamicValueList1 = getColumnWidthList(paramReport);
    DynamicValueList localDynamicValueList2 = getRowHeightList(paramReport);
    int i1 = i;
    int i2 = j;
    int i3 = 0;
    int i4 = 0;
    int i5 = -k;
    int i6 = i;
    while (true)
    {
      i5 += localDynamicValueList1.get(i6);
      if (i5 >= localDimension.getWidth())
      {
        i1 = i6;
        i3 = localDimension.width - i5 - localDynamicValueList1.get(i6);
        break;
      }
      ++i6;
    }
    i5 = -l;
    i6 = j;
    while (true)
    {
      i5 += localDynamicValueList2.get(i6);
      if (i5 >= localDimension.getHeight())
      {
        i2 = i6;
        i4 = localDimension.height - i5 - localDynamicValueList2.get(i6);
        break;
      }
      ++i6;
    }
    return new Point[] { new Point(i1, i2), new Point(i3, i4) };
  }

  public static String converNewReportletPath(String paramString)
  {
    String str;
    if (paramString == null)
      return null;
    if (paramString.toLowerCase().endsWith(".cpt"))
    {
      str = Utils.replaceAllString(paramString, "\\\\", "/");
      str = Utils.replaceAllString(str, "\\", "/");
      if (!(str.startsWith("/")))
        str = File.separator + str;
    }
    else
    {
      str = File.separator + Utils.replaceAllString(paramString, ".", "/") + ".class";
    }
    return str;
  }

  public static DynamicValueList getRowHeightList(Report paramReport)
  {
    if (paramReport == null)
      return new DynamicValueList(19);
    if (paramReport instanceof AbstractReport)
      return ((AbstractReport)paramReport).rowHeightList_DEC;
    if (paramReport instanceof PaginateReport)
    {
      if (((PaginateReport)paramReport).toRWorkSheet() == null)
        break label72;
      return ((PaginateReport)paramReport).toRWorkSheet().rowHeightList_DEC;
    }
    if (paramReport instanceof ExcelReport)
      return ((ExcelReport)paramReport).rowHeightList;
    label72: return createRowHeightList(paramReport);
  }

  public static DynamicValueList createRowHeightList(ReportGetter paramReportGetter)
  {
    int i = paramReportGetter.getRowCount();
    DynamicValueList localDynamicValueList = new DynamicValueList(19, i);
    for (int j = 0; j < i; ++j)
      localDynamicValueList.set(j, paramReportGetter.getRowHeight(j));
    return localDynamicValueList;
  }

  public static DynamicValueList getColumnWidthList(Report paramReport)
  {
    if (paramReport instanceof AbstractReport)
      return ((AbstractReport)paramReport).columnWidthList_DEC;
    if (paramReport instanceof PaginateReport)
    {
      if (((PaginateReport)paramReport).toRWorkSheet() == null)
        break label58;
      return ((PaginateReport)paramReport).toRWorkSheet().columnWidthList_DEC;
    }
    if (paramReport instanceof ExcelReport)
      return ((ExcelReport)paramReport).columnWidthList;
    label58: return createColumnWidthList(paramReport);
  }

  public static DynamicValueList createColumnWidthList(ReportGetter paramReportGetter)
  {
    int i = paramReportGetter.getColumnCount();
    DynamicValueList localDynamicValueList = new DynamicValueList(72, i);
    for (int j = 0; j < i; ++j)
      localDynamicValueList.set(j, paramReportGetter.getColumnWidth(j));
    return localDynamicValueList;
  }

  public static boolean isNull(Object paramObject)
  {
    return ((paramObject == null) || (paramObject == Primitive.NULL) || ((paramObject instanceof Formula) && (isNull(((Formula)paramObject).getResult()))));
  }

  public static void clearFormulaResult(FineBook paramFineBook)
  {
    int i = 0;
    int j = paramFineBook.getReportCount();
    while (i < j)
    {
      clearFormulaResult(paramFineBook.getReport(i));
      ++i;
    }
  }

  public static void clearFormulaResult(Report paramReport)
  {
    Iterator localIterator = paramReport.cellIterator();
    while (true)
    {
      CellElement localCellElement;
      do
      {
        if (!(localIterator.hasNext()))
          return;
        localCellElement = (CellElement)localIterator.next();
      }
      while (!(localCellElement.getValue() instanceof Formula));
      ((Formula)localCellElement.getValue()).setResult(null);
    }
  }

  public static Object convertGeneralStringAccordingToExcel(Object paramObject)
  {
    if ((paramObject != null) && (paramObject instanceof String))
    {
      String str = (String)paramObject;
      if (str.startsWith("="))
        return new Formula(str);
      if (str.length() > 0)
      {
        if (str.matches("\\(\\d+(\\.\\d+)*\\)"))
          str = "-" + str.substring(1, str.length() - 1);
        Number localNumber = Utils.string2Number(str);
        if (localNumber != null)
          return localNumber;
      }
    }
    return paramObject;
  }
}